using System;
using System.Collections.Generic;
using System.Text;

using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;

namespace Evaluant.EussDSL
{
    /// <summary>
    /// Redefinition of the serialization of an Entity
    /// </summary>
    public partial class EntitySerializer
    {
        private void CustomConstructor()
        {
            DefaultConstructor();
        }

        private string CustomXmlTagName
        {
            get { return DefaultXmlTagName; }
        }

        private string CustomMonikerTagName
        {
            get
            {
                //return DefaultMonikerTagName;
                return @"Reference";

            }
        }

        private string CustomMonikerAttributeName
        {
            get { return DefaultMonikerAttributeName; }
        }

        private void CustomRead(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
        {
            DefaultRead(serializationContext, element, reader);
        }

        private static void CustomReadPropertiesFromAttributes(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
        {
            DefaultReadPropertiesFromAttributes(serializationContext, element, reader);
        }

        private static void CustomReadElements(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader)
        {
            DefaultReadElements(serializationContext, element, reader);
        }

        private DslModeling::ModelElement CustomTryCreateInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::Partition partition)
        {
            return DefaultTryCreateInstance(serializationContext, reader, partition);
        }

        private DslModeling::ModelElement CustomCreateInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::Partition partition)
        {
            return DefaultCreateInstance(serializationContext, reader, partition);
        }

        private DslModeling::Moniker CustomTryCreateMonikerInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::ModelElement sourceRolePlayer, global::System.Guid relDomainClassId, DslModeling::Partition partition)
        {
            return DefaultTryCreateMonikerInstance(serializationContext, reader, sourceRolePlayer, relDomainClassId, partition);
        }

        private DslModeling::Moniker CustomCreateMonikerInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::ModelElement sourceRolePlayer, global::System.Guid relDomainClassId, DslModeling::Partition partition)
        {
            return DefaultCreateMonikerInstance(serializationContext, reader, sourceRolePlayer, relDomainClassId, partition);
        }

        private void CustomWrite(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer, DslModeling::RootElementSettings rootElementSettings)
        {
            DefaultWrite(serializationContext, element, writer, rootElementSettings);
        }

        private static void CustomWritePropertiesAsAttributes(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer)
        {
            DefaultWritePropertiesAsAttributes(serializationContext, element, writer);
        }

        private static void CustomWriteElements(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer)
        {
            DefaultWriteElements(serializationContext, element, writer);
        }

        private void CustomWriteMoniker(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlWriter writer, DslModeling::ModelElement sourceRolePlayer, DslModeling::DomainRelationshipXmlSerializer relSerializer)
        {
            //DefaultWriteMoniker(serializationContext, element, writer, sourceRolePlayer, relSerializer);

            #region Check Parameters
            global::System.Diagnostics.Debug.Assert(serializationContext != null);
            if (serializationContext == null)
                throw new global::System.ArgumentNullException("serializationContext");
            global::System.Diagnostics.Debug.Assert(element != null);
            if (element == null)
                throw new global::System.ArgumentNullException("element");
            global::System.Diagnostics.Debug.Assert(writer != null);
            if (writer == null)
                throw new global::System.ArgumentNullException("writer");
            global::System.Diagnostics.Debug.Assert(sourceRolePlayer != null);
            if (sourceRolePlayer == null)
                throw new global::System.ArgumentNullException("sourceRolePlayer");
            global::System.Diagnostics.Debug.Assert(relSerializer != null);
            if (relSerializer == null)
                throw new global::System.ArgumentNullException("relSerializer");
            #endregion

            if (sourceRolePlayer is EntityShape)
            {

                string monikerString = this.CalculateQualifiedName(serializationContext.Directory, element);
                global::System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(monikerString));
                writer.WriteStartElement(this.MonikerTagName);
                writer.WriteAttributeString(this.MonikerAttributeName, monikerString);
                writer.WriteEndElement();

            }
            else
            {

                string monikerString = this.CalculateQualifiedName(serializationContext.Directory, element);
                global::System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(monikerString));
                //writer.WriteStartElement(this.MonikerTagName);
                writer.WriteAttributeString(this.MonikerAttributeName, monikerString);
                //writer.WriteEndElement();

            }
        }

        private string CustomCalculateQualifiedName(DslModeling::DomainXmlSerializerDirectory directory, DslModeling::ModelElement element)
        {
            return DefaultCalculateQualifiedName(directory, element);
        }

        private string CustomGetMonikerQualifier(DslModeling::DomainXmlSerializerDirectory directory, DslModeling::ModelElement element)
        {
            return DefaultGetMonikerQualifier(directory, element);
        }
    }
}

